package com.soldier.medical.web.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author soldier
 * @Date 2020/3/10 13:36
 * @Version 1.0
 * @Description: 作者过滤器
 */
public class AuthorFilter implements Filter {

    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //判断Session
        HttpSession httpSession = ((HttpServletRequest) request).getSession();
        if (httpSession.getAttribute("username") == null) {
            ((HttpServletResponse) response).sendRedirect("/medical/login.jsp");
        } else {
            //放行
            chain.doFilter(request, response);

        }

    }

    public void init(FilterConfig config) throws ServletException {


    }

}
